//
//  ProfileEditViewController.m
//  zhijian
//
//  Created by lcb on 2019/2/24.
//  Copyright © 2019 lcb. All rights reserved.
//

#import "ProfileEditViewController.h"
#import "LTPlaceholderTextView.h"
#import "LTLimitTextField.h"
@interface ProfileEditViewController ()<UITextViewDelegate>
@property (nonatomic, strong) UIView * feedView;
@property (nonatomic, strong) LTPlaceholderTextView * textView;

@end

@implementation ProfileEditViewController
@synthesize navTitle=_navTitle;
@synthesize profileType=_profileType;
- (void)viewDidLoad {
    [super viewDidLoad];

    [self hyb_navWithLeftImage:@"back" title:_navTitle rightTitle:@"提交" leftClicked:^(UIButton *sender) {
        [self.navigationController popViewControllerAnimated:YES];
    } rightClicked:^(UIButton *sender) {
        [self sendFeedBack];
    }];
    // Do any additional setup after loading the view.
    [self initUI];
}
-(void)initUI
{
    self.feedView = [[UIView alloc]init];
    _feedView.backgroundColor = [UIColor whiteColor];
    _feedView.frame = CGRectMake(20, 104, SCREEN_WIDTH- 40, 150);
    [self.view addSubview:_feedView];
    //
    self.textView.frame =CGRectMake(0, 0, _feedView.frame.size.width, 100);
   
    [_feedView addSubview:self.textView];
    //

    
}
-(LTPlaceholderTextView *)textView{
    
    if (!_textView) {
        _textView = [[LTPlaceholderTextView alloc]initWithFrame:CGRectZero];
        _textView.backgroundColor = [UIColor whiteColor];
        _textView.delegate = self;
        _textView.font = [UIFont systemFontOfSize:14.f];
        _textView.textColor = [UIColor blackColor];
        _textView.textAlignment = NSTextAlignmentLeft;
        _textView.editable = YES;
        _textView.layer.cornerRadius = 4.0f;
        _textView.layer.borderColor = [UIColor grayColor].CGColor;
        _textView.layer.borderWidth = 0.5;
        if ([_profileType isEqualToString:@"name"]) {
            _textView.placeholder = @"输入您的姓名~";
        }else if ([_profileType isEqualToString:@"company"]) {
            _textView.placeholder = @"输入您的企业~";
        }else if ([_profileType isEqualToString:@"profession"]) {
            _textView.placeholder = @"输入您的职业~";
        }else if ([_profileType isEqualToString:@"password"]) {
            _textView.placeholder = @"输入您的密码~";
        }
    }
    
    return _textView;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [_textView resignFirstResponder];
}

//按下Done按钮的调用方法，我们让键盘消失

-(void)sendFeedBack
{
    [self.textView resignFirstResponder];
    if (self.textView.text.length==0) {
        [BaseToast showAtTop:@"请输入内容！"];
        return;
    }
    if ([_profileType isEqualToString:@"name"]) {
        [[Api sharedApi] updateUserInfo:@"" userName:self.textView.text callback:^(ApiResponse * _Nonnull response, NSString * _Nonnull errorMsg) {
            [BaseToast show:response.message];
            [[BaseShare sharedBaseShare] getUserInfo];
        }];
    }else if ([_profileType isEqualToString:@"password"]) {
        [[Api sharedApi] resetPwd:[BaseShare md5:self.textView.text] callback:^(ApiResponse * _Nonnull response, NSString * _Nonnull errorMsg) {
            [BaseToast show:response.message];
            [[BaseShare sharedBaseShare] getUserInfo];
        }];
    }
  
}
@end
